package com.dt76.smallloanbackenduser.controller.xm;

import com.dt76.smallloanbackenduser.pojo.afterloan.RepaymentInfo;
import com.dt76.smallloanbackenduser.pojo.xm.FcCheckState;
import com.dt76.smallloanbackenduser.remote.xm.DashboardRemote;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/xm")
public class DashboardController {

    @Resource
    private DashboardRemote dashbordRemote;

    @RequestMapping("/dashboard")
    public String qryAllInfo(Model model){

        int borrowCount = dashbordRemote.qryBorrowCount();

        List<FcCheckState> checkStates = dashbordRemote.qryBorrowMoney();

        long approveMoneys = 0;
        for(FcCheckState checkState: checkStates){
            approveMoneys += checkState.getmApproveMoney();
        }

        List<RepaymentInfo> repaymentInfos = dashbordRemote.qryLoanMoney();

        double money = 0.0;
        for(RepaymentInfo repaymentInfo: repaymentInfos){
            money += (repaymentInfo.getInterest()+repaymentInfo.getPrincipal());
        }

        int secondCount = dashbordRemote.qrySecondCount();

        int laterCount = dashbordRemote.qryLaterCount();

        int lendCount = dashbordRemote.qryLendCount();

        int overCount = dashbordRemote.qryOverCount();

        model.addAttribute("borrowCount",borrowCount);

        model.addAttribute("approveMoneys",approveMoneys);

        model.addAttribute("money",money);

        model.addAttribute("secondCount",secondCount);

        model.addAttribute("laterCount",laterCount);

        model.addAttribute("lendCount",lendCount);

        model.addAttribute("overCount",overCount);

        return "/pages/xm/dashboard";
    }


}
